package com.commonUtil.util;

import lombok.Data;

import java.io.Serializable;

@Data
public class ResultCode implements Serializable {
    private int code;
    private String msg;
    private Object data;

    /**
     * 封装状态码
     * @param code
     * @param msg
     * @param data
     * @return
     */
    public static ResultCode success(int code,String msg,Object data){
        ResultCode resultCode = new ResultCode();
        resultCode.setCode(code);
        resultCode.setMsg(msg);
        resultCode.setData(data);
        return resultCode;
    }

    /**
     * 二次封装状态码进行调用
     * @param data
     * @return
     */
//    返回成功数据状态码
    public static ResultCode success(Object data){
        return success(20000,"操作成功",data);
    }
    public static ResultCode result(Object data){
        return success(20000,"操作成功",data);
    }



    public static ResultCode Error(int code,String msg,Object data){
        ResultCode resultCode = new ResultCode();
        resultCode.setCode(code);
        resultCode.setMsg(msg);
        resultCode.setData(data);
        return resultCode;
    }
//    返回失败的状态码
    public static ResultCode Error(){
        return Error(20002,"操作失败",null);
    }
}
